package tv.dyndns.kishibe.client.util;

import com.google.gwt.core.client.GWT;

public class ImageCache {
	private static final String URL_PREFIX = GWT.isScript() ? "http://kishibe.dyndns.tv/QMAClone/image"
			: "http://127.0.0.1:8888/image";
	private static final char[] HEX = "0123456789abcdef".toCharArray();

	private ImageCache() {
	}

	public static String getUrl(String url, int width, int height) {
		return URL_PREFIX + "/url/" + encode(url) + "/width/" + width + "/height/" + height;
	}

	private static String encode(String s) {
		StringBuilder sb = new StringBuilder();
		for (char ch : s.toCharArray()) {
			sb.append(HEX[ch / 16]).append(HEX[ch % 16]);
		}
		return sb.toString();
	}
}
